/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package database;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.Order;

/**
 *
 * @author Trang
 */
public class MoreInventoryDAO {
    private Connection con;

    public MoreInventoryDAO() {
        con = DBFactory.createConnection("onlineshopping");
    }
    public Date OrderTime(String pname) {
       Date result = new Date();

        try {
            String sqlst = "Select * from OrderLog where name = ? Order  by OrderTime DESC Limit 1";
            PreparedStatement ps = con.prepareStatement(sqlst);
            
            ps.setString(1, pname);
            ResultSet rs = ps.executeQuery();

            if (rs.next()) {
                Date OrderTime = rs.getDate("OrderTime");
                result = OrderTime;
                }
            else result = new Date(0, 0, 0);
        } catch (SQLException ex) {
            Logger.getLogger(OrderDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return result;
    }
    public Date ReceiptTime(String pname) {
       Date result = new Date();

        try {
            String sqlst = "Select * from ReceipLog where name = ? Order  by ReceiptTime DESC Limit 1";
            PreparedStatement ps = con.prepareStatement(sqlst);
            
            ps.setString(1, pname);
            ResultSet rs = ps.executeQuery();

            if (rs.next()) {
                Date ReceiptTime = rs.getDate("ReceiptTime");
                result = ReceiptTime;
                }
        } catch (SQLException ex) {
            Logger.getLogger(OrderDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return result;
    }
}
